#include "userconfig.h"
#include "at32f421_bsp.h"
#include "gmsi.h"
// object
#include "captureimg.h"
#include "correspondent.h"
#include "flashled.h"

gmsi_t tGmsi = {
    .ptData = NULL,
    //.pfcnLedSet = bsp_LedSet
};

// object correspondent
correspondent_cfg_t tCorrespondentCfg = {
    // uart
    .Read = usart_receiveData,
    .Write = usart_sendData,
    .wFd = 0,
};
correspondent_t tCorrespondent;

flashled_cfg_t tFlashledCfg = {
    // 485
    .Read = usart_receiveData,
    .Write = usart_sendData,
    .wFd = 1,
};
flashled_t tFlashled;

captureimg_cfg_t tCaptureimgCfg = {

};
captureimg_t tCaptureimg;

int main(void)
{
    system_clock_config();
    bsp_Init();
    utildebug_LedInit(bsp_LedSet);
    
    correspondent_Init((uintptr_t)&tCorrespondent, (uintptr_t)&tCorrespondentCfg);
    flashled_Init((uintptr_t)&tFlashled, (uintptr_t)&tFlashledCfg);
    captureimg_Init((uintptr_t)&tCaptureimg, (uintptr_t)&tCaptureimgCfg);
    // init object in gmsi
    gmsi_Init(&tGmsi);
    
    while(1)
    {
        utildebug_LedBreathe(NULL);
        gmsi_Run();
    }
    return 0;
}

void SysTick_Handler(void)
{
    gmsi_Clock();
    
    USART1_TimeOutCounter();
    USART2_TimeOutCounter();
}
